Lab Assignment # 2, CSE 1320-501,Spring 2004

 

Topic objectives:                                Pointers and space allocation

                                Strings

                                More control structures

                                Functions, parameter passing, side effects

 

Now that you have framed some pictures, you realize that your art collection of pictures and sculptures and other works has grown to fairly large proportions so you decide to create a program to review and analyze the pieces in the collection.  You especially want to keep track of the most expensive piece (for insurance purposes) and the largest piece (for storage purposes.)

 

Your input will come from the user of the program (you or whomever enters your artworks [the curator of your private museum?]) who will type in seven (7) pieces of information about each piece of art.  There will be three lines of input from the keyboard for each piece of art.  Each work will have the following information:

 

Title_of_artwork 

Artist_name

Medium  Artwork_value  Height  Width  Depth

 

The first line will be the title of the artwork which should be read into a buffer and then saved into a string if needed.  Examples of titles would be:

Title_of_artwork 

 

Persistence of Memory

   or

Improvisation 26 - Oars

 

The second line of data would be the artist’s name in last name, first name order which will be read into a buffer and then saved into a string if needed. There must be a comma between last and first names and assume that if the artist has a middle initial that it is just part of the first name.  If the artist is not known, the line should just say Unknown.  For the works above, the artists would be:

Artist_name

 

Dali, Salvador

  and

Kandinsky, Vassily

 

The third line for each piece of work would give five pieces of information which should be read in as a char, a long double, and three ints.  First, the medium of the artwork as a single letter abbreviation, i.e. painting(A), photo(O), print(I), wood(W), stone(S), ceramic(C), textile(T), or something else(E). Next, the value of the artwork (including framing cost and appreciation over time) as a floating point number.  This is followed by the height, width, and depth of the piece of art in centimeters as three integers.   For the two above (assuming the actual Dali painting and a print of the Kandinsky):

Medium  Artwork_value  Height  Width  Depth

 

A  1000000000.00 24  33 3

  and

I  120.00 50 50 2

 

Your program should do the following:

 

1)       Read in the title of the artwork

2)       Read in the name of the artist

3)       Read in the five pieces of data abut the artwork

4)       Compare the value of the artwork to the highest valued piece you have read so far.  If the new work is of higher value save it as the new highest value work.  Save this in a set of Value variables – Value_title, Value_artist, Value_medium, Value_work, Value_ht, Value_wd, Value_dp.

5)       Next compare the size of the artwork to the largest work seen so far.  If the new work is larger, save it in a set of Large variables similar to above.  Compare the sizes as follows:

a.       First compare the current largest area (height * width) with the area of the new work.  If the new work is larger, keep it as the new largest work.

b.      If the two works are the same in area, then compare depth and keep the one with the largest depth.

c.       If the total volumes are the same (height * width * depth), then compare the mediums and choose based on the following order:  Prefer S over W over E over C over A over O over I over T.

d.      If everything is the same, keep the existing largest item.

6)       For the artwork just read, use a switch statement based on the medium to print out its information as follows:

a.       For A, print “The painting Title_of_artwork by Artist_name is Height by Width centimeters and is valued at Artwork_value

b.      For O, print “The photograph Title_of_artwork by Artist_name is Height by Width centimeters and is valued at Artwork_value

c.       For I, print “The print Title_of_artwork by Artist_name is Height by Width centimeters and is valued at Artwork_value

d.      For W, print “The wood work Title_of_artwork by Artist_name is Height by Width by Depth centimeters and is valued at Artwork_value

e.       For S, print “The stone work Title_of_artwork by Artist_name is Height by Width by Depth centimeters and is valued at Artwork_value

f.        For C, print “The ceramic Title_of_artwork by Artist_name is valued at Artwork_value and is Height by Width by Depth centimeters”

g.       For T, print “The textile work Title_of_artwork by Artist_name is valued at Artwork_value and is Height by Width by Depth centimeters”

h.      For E, print “The artwork Title_of_artwork is valued at Artwork_value,  is Height by Width by Depth centimeters and was created by Artist_name

7)       Ask the user if there are more items to enter.  If ‘Yes’ return to step 1) above, else for ‘No’ continue to the step labeled 8)

8)       When the user has finished entering all the items, print out a message telling which was the highest Value (from 4 above) item and which was the Largest (from 5 above) item along with the title, artist and other info for each.

 

Implementation requirements:

The program must use the following data structures and types:

Strings that are allocated for Title and Artist when those values are to be saved as the Value or  Large items  - use a char * type and either malloc or calloc

Two buffers (char array or pointer to char with allocated space) to use to read in the Title and Artist for each new item - just reuse the same buffers each time

A char, long double, and three ints for the data values read in

 

The program must use the following control structures:

A switch to handle the output messages by category

Function calls to perform the tasks 4, 5, and 6 - use at least two functions in addition to main and pass ALL parameters explicitly (no global variables allowed but reference parameters may be used)

 

The program should perform the following actions in the given order:

Declare and initialize the variables

Print a short introduction to the system for the user

Get the needed input values from the keyboard

Compare and keep track of the Value and Large items, allocating strings as needed and freeing the space of now-unneeded strings

Print the appropriate outputs

Let the user enter additional values until the user indicates that they are finished.

Print the final values for Value and Large

 

As in Lab #1, the program should have a program header which gives, at least, your name, the number of the lab assignment, your class and section, the assignment date, the due date, and a description of the program.  If multiple files are used, each file should contain a similar header. 

Each programmer-defined function, i.e. each function you write, should have a function header similar to those used in the examples in the textbook.  This header should include at least the function name, the purpose of the function, and its inputs and outputs.

 

This program must be run using the sample data that is given below AND must be run using your own sample data as well (at least 5 additional items).  The sample data set that you create must meet the guidelines given in the problem definition.

 

The program output must be recorded in a script file from OMEGA using the gcc compiler.  If you do not know how to create a script file, it is your responsibility to read the instructions on  my website and to  ask the TA or OIT how to use this function.   REMINDER:  Do NOT name the script file the same as the source code file!  Use a .txt or .dat extension on the script file.

 

Sample input values:  

 

Esker Trefoil Torus

Ferguson, Helaman

S 18000.00 250 400 300

 

 

La Betes du la Mer

Matisse, Henri

O 35000.00 225 80 4

 

In The Courtyard

Schou, Sandra

A 450.00 35 65 3

 

Mother and Child

Williams, Mildred

A 200.00 85 40 2

 

Emerald Vase

de Tirtoff, Romain (Erte)

I 22000.00 22 18 2

 

 

Grading scale:

Code:     (72%)

                Headers, Style, Modularity (20 points)

Program header and function headers for all functions

Style (indentation, consistency, meaningful identifiers, lateral separation of code from line comments, etc.)

Modularity (division of the problem into small tasks, each one assigned to its own function and called from main() or from another function when appropriate--do not code the entire program in main!)

Correct manipulation of the string including declaration and memory allocation  (12 points)

Correct use of required control structures (8 points)

Correct maintenance of Value and Large information (12 points)

Correct function structure as required (8 points)

Proper implementation of input and user control (12 points)

Output:          (28%)

                Output follows the form given above - tasks 6 and 8  (16 points)

                Output (can be more than one session of running the program)  contains all the sample data and at least 5 more additional input values  (12 points)